﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.ComponentModel;
namespace OtherDevice
{
    [Description("光源控制器-HY")]
    public class HY_New_LightCtrl : LightCtrlBase
    {
        public HY_New_LightCtrl(string strName) : base(strName)
        {
            controlFrom = new XNCLightCtrl();
        }

        public override int Get(int channel)
        {
            throw new NotImplementedException();
        }
        public override bool Set(int channel, int value)
        {
            try
            {
                value = value > 100 ? 100 : value;
                value = value < 0 ? 0 : value;
                channel++;
                string v = value.ToString();

                if (v.Length == 1)
                {
                    v = "00" + v;
                }
                else if (v.Length == 2)
                {
                    v = "0" + v;
                }
                string cmd = $"ch{channel}=0{v}\r\n";
                byte[] byteRe = new byte[2];
                return SendAndReciveData(cmd, ref byteRe, 500);

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show($"光源设置失败{ex}");
                return false;
            }
        }
    }
}
